Ext.onReady(function() {
	
//	if (msg && msg == 'timeout') {
//		Ext.get('messagePanel').dom.innerHTML = "用户信息过期,请重新登录!";
//	}
//	if (msg && msg == 'logoff') {
//		Ext.get('messagePanel').dom.innerHTML = "注销成功,欢迎再次使用!";
//	}
	
	document.onkeydown = function(e) {
		if (!e)
			e = window.event;
		if ((e.keyCode || e.which) == 13) {
			if (document.all) {
				document.getElementById('btn_logon').click();
			} else {
				var evt = document.createEvent("MouseEvents");
				evt.initEvent("click", true, true);
				document.getElementById('btn_logon').dispatchEvent(evt);
			}
		}
	}

	Ext.get('btn_logon').on('click', function() {
		var userName = Ext.get('userName').dom.value;
		var userPwd = Ext.get('userPwd').dom.value;
		var errorMsg = "";
		if (!userName || !userPwd) {
			errorMsg += "用户名或密码不能为空！<br/>";
		}
		var errorImg = "<img style='vertical-align:middle;'  src='"
				+ Acc.Config.ContextPath + "/resources/images/error.png' />";
		if (!errorMsg) {
			var myMask = new Ext.LoadMask(Ext.getBody(), {
						msg : "正在验证,请稍等..."
					});
			myMask.show();

			Ext.Ajax.request({
						url : Acc.Config.ContextPath + '/user/login.do',
						method : "POST",
						params : {
							'userName' : userName,
							'userPwd' : userPwd,
							'security' : 'noFilter'
						},
						success : function(resp) {
							var data = Ext.util.JSON.decode(resp.responseText);
							if (data.success) {
								window.location.href = Acc.Config.ContextPath + '/jsp/index.jsp';
								//window.location.href = Acc.Config.ContextPath + '/admin/index.do';
							} else {
								myMask.hide();
								Ext.get('messagePanel').dom.innerHTML = errorImg
										+ data.error;
							}
						},
						failure : function(resp) {
							myMask.hide();
							var data = Ext.util.JSON.decode(resp.responseText);
							Ext.get('messagePanel').dom.innerHTML = errorImg
									+ data.error;
						},
						scope : this
					});
		} else {
			Ext.get('messagePanel').dom.innerHTML = errorImg + errorMsg;
		}
	});
});